package ac.il.technion.cs236369.hw5.core.entities;

import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: User
 *
 */
@Entity
@Table( name="users")
public class User implements Serializable {

	@Id
	@Column(name="login", unique=true, nullable=false)
	private String loginName;
	@Column(name="pwd", nullable=false)
	private String password;
	@Column(name="firstName", nullable=false, length=25)
	private String firstName;
	@Column(name="lastName", length=25)
	private String lastName;
	@OneToOne
	@JoinColumn( name="role_id")
	private Role permission;
	@Column(name="phone")
	private String phoneNumber;
	@Column(name="activityStatus")
	private Date activityStatus;
	@OneToMany( mappedBy="user", cascade=CascadeType.ALL)
	private Collection<Order> orders = new ArrayList<Order>();
	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable( name="user_projects",
			joinColumns=@JoinColumn(name="userId"),
			inverseJoinColumns=@JoinColumn(name="projectId"))
	private Collection<Project> projects = new ArrayList<Project>( );
	
	
	private static final long serialVersionUID = 1L;

	public User() {
		super();
	}   
	public String getLoginName() {
		return this.loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}   
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}   
	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}   
	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}   
	public Role getPermission() {
		return this.permission;
	}

	public void setPermission(Role permission) {
		this.permission = permission;
		permission.getUsers().add(this);
	}   
	public String getPhoneNumber() {
		return this.phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}   
	public Date getActivityStatus() {
		return this.activityStatus;
	}

	public void setActivityStatus(Date activityStatus) {
		this.activityStatus = activityStatus;
	}

	public Collection<Order> getOrders() {
		return orders;
	}
	
	public void setOrders(Collection<Order> orders) {
		this.orders = orders;
	}
	
	public Collection<Project> getProjects() {
		return projects;
	}
	
	public void setProjects(Collection<Project> projects) {
		this.projects = projects;
	}

	
}
